P.Mod.cps_demo = function (dom,options) {
	this.dom = dom;
	this.result = $("div[dom='result']",dom)
	this.spanDoms = $.UT.DomSelector($("span",dom));
    this.aDoms = $.UT.DomSelector($("a",dom));
    this.cps = P.Set.DocCps;
	var _this = this;
    this.cps.subscribe("price");
    this.cps.subscribe("user-info");
    this.cps.dom.bind("cpsChange",function(e,cps){
        if(cps.options.type == 0){
            $(_this.spanDoms["cps-type"]).html("ajax");
            $(_this.spanDoms["states"]).html(cps.netStatus);
        }else{
            $(_this.spanDoms["cps-type"]).html("cps");
            $(_this.spanDoms["states"]).html(cps.netStatus);
        }
        if(cps.netStatus == "success"){
            _this.result.html(cps.data.price);
        }
    });

    this.cps.dom.bind("cpsTimer",function(e,cps){
       $(_this.spanDoms["countdown"]).html(cps.countdown);
    });
    
    $(this.aDoms["cps"]).click(function(e){
        _this.cps.run({type:1});
        return false;
    });
    $(this.aDoms["ajax"]).click(function(e){
        _this.cps.run({type:0});
        return false;
    });
	$(this.aDoms["abort"]).click(function(e){
        _this.cps.abort();
        return false;
    });
    $(this.aDoms["running"]).click(function(e){
        _this.cps.run();
        return false;
    });
    $(this.aDoms["press"]).click(function(e){
        _this.cps.soon();
        return false;
    });
    
};
$('#cps_demo').Module();
